package com.example.mapper;

import com.example.entity.vo.pc.AutoBTdan;
import com.example.entity.yifei.Moctc;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Lan
 * @since 2024-07-30
 */
public interface MoctcMapper extends BaseMapper<Moctc> {

    @Select("SELECT ISNULL(CAST(CAST(MAX(TC002) AS NUMERIC(11))+1 AS CHAR(11)) ,CONVERT(CHAR(8),GETDATE(),112)+'001') AS moctcId \n" +
            "FROM MOCTC WHERE TC002 LIKE CONVERT(CHAR(8),GETDATE(),112)+'%' AND TC001 = #{llType}")
    String newDh(String llType);

//    @Insert("INSERT INTO MOCTC(COMPANY,CREATOR,CREATE_DATE,FLAG,TC001,TC002,TC003,TC004,TC005,TC006,TC007,TC008,TC009,TC010,TC011,TC012,TC013,TC014,TC015,TC016,TC017,TC018,TC019,TC020,TC021,TC028,TC029,TC030,TC031,UDF01,UDF02,UDF03,UDF04,UDF05) \n" +
//            "SELECT (SELECT COMPANY FROM CMSMD WHERE MD001 = #{workCenter}) COMPANY, #{curUser} ,REPLACE(REPLACE(REPLACE(convert(char(20),getdate(),120),'-',''),':',''),' ',''),1, #{llType} , #{moctcId} ,CONVERT(CHAR(8),GETDATE(),112),'001', #{workCenter} ,'','','54','N',0,'N','1','Y',CONVERT(CHAR(8),GETDATE(),112),'','N',0,'0','','','','',0,0,'********************','','','','','' \n" +
//            "WHERE NOT EXISTS(SELECT * FROM MOCTC WHERE TC001= #{llType} AND TC002= #{moctcId})")
    void insertMoctc(String curUser, String llType, String moctcId, String workCenter, String supplier, String llTypeNo, String llDate);

    void insertMocte(@Param("t") AutoBTdan t, @Param("curUser") String curUser);

    void delMocte(@Param("type")String type, @Param("id")String id, @Param("no")String no);

    void delMoctcNoMocte(@Param("type")String type, @Param("id")String id);

    @Insert("INSERT INTO MOCTC(COMPANY,CREATOR,CREATE_DATE,FLAG,TC001,TC002,TC003,TC004,TC005,TC006,TC007,TC008,TC009,TC010,TC011,TC012,TC013,TC014,TC015,TC016,TC017,TC018,TC019,TC020,TC021,TC028,TC029,TC030,TC031,UDF01,UDF02,UDF03,UDF04,UDF05) \n" +
            "SELECT (SELECT COMPANY FROM CMSMD WHERE MD001 = #{workCenter}) COMPANY, #{curUser} ,REPLACE(REPLACE(REPLACE(convert(char(20),getdate(),120),'-',''),':',''),' ',''),1, #{llType} , #{moctcId} ,CONVERT(CHAR(8),GETDATE(),112),'01', #{workCenter} ,#{supplier},'',#{llTypeNo},'N',0,'N','1','Y',#{llDate},'','N',0,'0','','','','',0,0,'********************','','','','','' \n" +
            "WHERE NOT EXISTS(SELECT * FROM MOCTC WHERE TC001= #{llType} AND TC002= #{moctcId})")
    void insertMoctcTLD(String curUser, String llType, String moctcId, String workCenter, String supplier, String llTypeNo, String llDate);

    void insertMocteTLD(@Param("t") AutoBTdan t, @Param("curUser") String curUser);
}
